<?php
declare (strict_types=1);

namespace app\controller\admin;

use app\common\controller\BaseController;
use app\model\admin\Duty as dutyModel;
use think\App;
use \Throwable;

class Duty extends BaseController
{
    protected $model;

    public function __construct(App $app, dutyModel $model)
    {
        parent::__construct($app);
        $this->model = $model;
    }

    /**
     * 列表查询
     * @return array
     */
    public function query()
    {
        $where = [];
        $where['status'] = 1;
        $page = input('page/d', 1);
        $pageSize = input('page_size/d', 20);
        $order = null;
        $fields = 'id,store_id,re_id,re_type,duty_status,duty_status duty_status_text,status,store_id,store_id store_name,start_timestr,end_timestr,duty_date,create_time';
        return $this->model->getList($where, $fields, $order, $page, $pageSize);
    }

    /**
     * 启用
     * @return array
     */
    public function enable()
    {
        try {
            return $this->model->changeStatus($this->params, 1);
        } catch (Throwable $ex) {
            return $this->returnException($ex);
        }
    }

    /**
     * 禁用
     * @return array
     */
    public function disable()
    {
        try {
            return $this->model->changeStatus($this->params, 2);
        } catch (Throwable $ex) {
            return $this->returnException($ex);
        }
    }
}
